import {
  Body,
  Controller,
  Get,
  Param,
  Post,
  Query,
  UsePipes,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';

import { RoleServiceImpl } from '../service/impl/roleServiceImpl';
import {
  RoleDelteDto,
  RoleFindDto,
  RoleInsertDto,
  RoleListDto,
  RoleUpdateDto,
} from '../dto/role.dto';


@ApiBearerAuth()
@ApiTags('后台角色管理')
@Controller('admin/role')
export class RoleController {
  constructor(private readonly RoleServiceImpl: RoleServiceImpl) {}

  @ApiOperation({ description: '创建角色' })
  @Post('/insert')
  async insert(@Body() role: RoleInsertDto): Promise<unknown> {
    return await this.RoleServiceImpl.insert(role);
  }

  @ApiOperation({ description: '删除角色' })
  @Post('/delete')
  async delete(@Body() id: RoleDelteDto) {
    return await this.RoleServiceImpl.delete(id);
  }

  @ApiOperation({ description: '根据ID查找角色' })
  @Get('/find/:id')
  async find(@Param() params: RoleFindDto) {
    console.log(params);
    const { id } = params;
    return await this.RoleServiceImpl.find(id);
  }

  @ApiOperation({ description: '角色列表' })
  @Get('/list')
  async list(@Query() query?: RoleListDto) {
    console.log(query);
    return await this.RoleServiceImpl.list(query);
  }
  /**
   *
   * @param body
   */
  @ApiOperation({ description: '更新角色' })
  @Post('/update')
  async update(@Body() body: RoleUpdateDto) {
    return await this.RoleServiceImpl.update(body);
  }
}
